/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.app.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.renren.modules.app.dao.UserDao;
import io.renren.modules.app.dao.UserRegistrationDao;
import io.renren.modules.app.dao.UserWithCarNumberDao;

import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.entity.UserRegistrationEntity;
import io.renren.modules.app.entity.UserWithCarNumber;

import io.renren.modules.app.service.UserWithCarNumberService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


@Service("UserWithCarNumberService")
public class UserWithCarNumberServiceImpl extends ServiceImpl<UserWithCarNumberDao, UserWithCarNumber> implements UserWithCarNumberService {


	@Autowired
	private UserWithCarNumberDao userWithCarNumberDao;
	@Autowired
	private UserRegistrationDao userRegistrationDao;
	@Autowired
	private UserDao userDao;



	public UserWithCarNumber queryByuserID(int userId) {
		UserWithCarNumber withCarNumber = new UserWithCarNumber();
		UserEntity user = userDao.selectById(userId);
		if (user!=null) {
			withCarNumber.setUser(user);
		}
//		UserWithCarNumber withCarNumber = baseMapper.selectOne(new QueryWrapper<UserWithCarNumber>()
//				.eq("user_id", userId));
		UserRegistrationEntity userRegistrationEntity = userRegistrationDao.selectOne(new LambdaQueryWrapper<UserRegistrationEntity>()
				.eq(UserRegistrationEntity::getDriverid, userId)
				.last("limit 1")
		);
		if (userRegistrationEntity !=null) {
			withCarNumber.setCarNumber(userRegistrationEntity.getCarnumber());
		}
		return withCarNumber;
	}





}

